package com.lonewalker.completablefuturedemo;

import java.util.concurrent.CompletableFuture;

/**
 * @author LoneWalker
 * @date 2023/2/12
 * @description
 */
public class demo9 {
    public static void main(String[] args) {
        CompletableFuture<Integer> completableFuture1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("1号任务执行");
            return 5;
        });
        CompletableFuture<Integer> completableFuture2 = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("2号任务执行");
            return 6;
        });
        CompletableFuture<Void> result = CompletableFuture.anyOf(completableFuture1, completableFuture2).thenAccept(d -> {
            System.out.println("有任务完成");
        });
    }
}
